<?php

/**
 * グローバルナビ店舗用Utilクラス
 */
class Apm_Util_GlobalNavi_Shop {

	private $searchType = null;
	private $prefCdList = null;
	private $cityCdList = null;
	private $railCdList = null;
	private $params = null;
	
	function __construct()
	{
        $this->params = array();
        
        $this->searchType = Apm_Session_GlobalNavi::getSearchType();
        $this->prefCdList = Apm_Session_GlobalNavi::getPrefCdList();
        $this->cityCdList = Apm_Session_GlobalNavi::getCityCdList();
        $this->railCdList = Apm_Session_GlobalNavi::getRailCdList();

        // 検索区分を設定
        Apm_Session_GlobalNavi::setSearchType(Apm_Config_Search::SRHKBN_TENPO);
	}
	
	/**
	 * 画面遷移判定
	 */
	public function transitionJudge()
	{
		$this->params['SrhKbn'] = Apm_Config_Shop::SEARCH_KUBUN_MAP;

		//  店舗検索から遷移してきた場合
		if ($this->searchType == Apm_Config_Search::SRHKBN_TENPO)
		{
			// セッションクリア
			Apm_Session_GlobalNavi::clear();
//			Apm_Util::redirect(Apm_Config_Shop::URL_INDEX, $this->params);
			$this->params = array();
			$this->params['SrhType'] = Apm_Config_Shop::SEARCH_TYPE_CITY;
			return $this->params;
		}
		else
		{
//			$this->prefJudge();
			if (!$this->prefJudge()) {
				return $this->params;
			}
//			$this->searchTypeJudge();
			if (!$this->searchTypeJudge()) {
				return $this->params;
			}
        }
        return $this->params;
	}

	/**
	 * 都道府県判定
	 */
	private function prefJudge()
	{
		// 都道府県コードが選択されていない場合
		if (count($this->prefCdList) == 0)
		{
			// 店舗トップへリダイレクト
//			Apm_Util::redirect(Apm_Config_Shop::URL_INDEX, $this->params);
			$this->params = array();
			$this->params['SrhType'] = Apm_Config_Shop::SEARCH_TYPE_CITY;
			return false;
		}
		$this->params['SrhType'] = Apm_Config_Shop::SEARCH_TYPE_CITY;
		$this->params['PrefCd'] = $this->prefCdList;
		$this->params['prefcd_condition'] = Apm_Session_GlobalNavi::getPrefCdCondition();
		$this->params['first_check'] = Apm_Session_GlobalNavi::getFirstCheck();

		return true;
	}

	/**
	 * 市区町村or沿線判定
	 */
	private function searchTypeJudge()
	{
		// 市区町村コード、沿線コードが選択されていない場合
		if (count($this->cityCdList) == 0 && count($this->railCdList) == 0)
		{
			// 市区町村選択画面へリダイレクト
			$this->params['SrhType'] = Apm_Config_Shop::SEARCH_TYPE_CITY;
//			Apm_Util::redirect(Apm_Config_Shop::URL_SELECT_CITY, $this->params);
			$this->params['CityCd'] = array();
			return false;
		}
		// 市区町村コードが選択されている場合
		if (count($this->cityCdList) > 0)
		{
			$this->params['SrhType'] = Apm_Config_Shop::SEARCH_TYPE_CITY;
			$this->params['CityCd']  = $this->cityCdList;
		}
		// 沿線コードが選択されている場合
		if (count($this->railCdList) > 0)
		{
			$this->params['SrhType'] = Apm_Config_Shop::SEARCH_TYPE_RAIL;
			$this->params['RailCd']  = $this->railCdList;
		}
		
		// 店舗一覧へリダイレクト
//		Apm_Util::redirect(Apm_Config_Shop::URL_LIST, $this->params);

		return true;
	}

}
?>
